// pages/shopping/shopping.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        list:[
            {id:1,
            img:'/img/p1.png',
            title:'轻奢吧椅Y66',
            price:'8660.00',
            num:'2',
            checkstatus:'false'
            },
            {id:1,
            img:'/img/p2.png',
            title:'轻奢书椅Y69',
            price:'7520.00',
            num:'2',
            checkstatus:'false'
            },
        ],
        sum:0
    },
    changeCheck(e){
      this.setData({
        checkedstatus:!this.data.checkedstatus
      })
    },
    reduceTap: function(e){
        var index = e.currentTarget.dataset.index;
        var postList = this.data.list;
        let num = postList[index].num;
        if (num > 1) {
            num --;
        }
        postList[index].num = num;
        this.setData({
        list:postList
        });     
    },
    addTap: function(e){
        var index = e.currentTarget.dataset.index;
        var postList = this.data.list;
        var num = postList[index].num;
        var that = num;
        num ++;
        postList[index].num = num;
        this.setData({
        list:postList
        });     
    },
    getsum(e){
      var postList = this.data.list;
      for(let i = 0 ;i < postList.length;i ++){
        if(postList[i].checkedstatus == true){
          sum[i] = postList[i].price * postList[i].num
          sum = sum + sum[i]
        }return sum
      }
      this.setData({
        sum:sum
      })
      
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})